# 带参数的url
import requests
from urllib.parse import urlencode

# url='https://tieba.baidu.com/f?'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
}

# 方法一
# url='https://tieba.baidu.com/f?kw=%E5%AD%99%E7%AC%91%E5%B7%9D'
# response=requests.get(url, headers=headers)
# response.encoding='utf-8'
# print(response.text)

# 方法二
# url='https://tieba.baidu.com/f?'
# params={
#     'kw': '孙笑川'
# }
# response=requests.get(url, params=params, headers=headers)
# response.encoding='utf-8'
# print(response.text)

# 方法三

url = 'https://tieba.baidu.com/f?'
params = {
    'kw': '孙笑川'
}
# urlencode可以把字典对象转换为url的请求参数
new_url = url + urlencode(params)
response = requests.get(new_url, headers=headers)
response.encoding = 'utf-8'
print(response.text)
